function getxhr(){
	var xhr = false;
	if(window . XMLHttpRequest){
		xhr = new XMLHttpRequest();
	}else{
		xhr = window . ActiveXObject('Microsoft . XMLHttp');
	}
	return xhr;
}

function attr(obj){

	var xhr = getxhr();
	var url = 'goods.php?act=attr_oper&cat_id=' + obj.value;
	
	xhr.open('GET', url, true);
	
	xhr.onreadystatechange = function (){
		if(xhr.readyState == 4){
			var attr_list = eval('(' + this.responseText + ')');

			var html = '';

			for(var i=0,len=attr_list.length; i<len; i++){
				
				html += '<tr class="trs">';
				html += '<td class="label">' + attr_list[i]['attr_name'] + '：</td>';
				if(attr_list[i]['attr_input_type'] == '列表中选择'){
					html += '<td><select name="' + attr_list[i]['attr_id'] + '" ><option value="0">请选择...</option>';
					var str = attr_list[i]['attr_values'];
					var arr = str.split(',');
					for(var j=0,len2=arr.length; j<len2; j++){
						html += '<option value="' + arr[j] + '">' + arr[j] +'</option>';
					}
					html += '</select></td>';
				}else if(attr_list[i]['attr_input_type'] == '手工录入'){
					html += '<td><input type="text" name="' + attr_list[i]['attr_id'] + '" /></td>';
				}else if(attr_list[i]['attr_input_type'] == '多行文本框'){
					html += '<td><textarea name="' + attr_list[i]['attr_id'] + '" cols="40" rows="3"></textarea></td>';
				}
				
				html +='</tr>';
			}

			$(".trs").remove();
			$("#location").after(html);
		}

	}
	xhr.send(null);
	
}

window . onload = function (){
	var sel = document.getElementsByName('cat_id')[0];
	attr(sel);
}

/**
function attr(obj){
	
	var xhr = getxhr();
	var url = 'goods.php?act=attr_oper&cat_id=' + obj.value;
	
	xhr.open('GET', url, true);
	
	xhr.onreadystatechange = function (){
		if(xhr.readyState == 4){
			var attr_list = eval('(' + this.responseText + ')');
			
			var html = '';
			$.each(attr_list, function(index, content){
				
				html += '<tr class="trs">';
				$.each(content, function(index2, content2){
					//html += '<td>下标'+index2+'是'+content2+'</td>';
					if(index2 == 'attr_values'){
						var str = content2;
					}
					
					if(index2 == 'attr_name'){
						var temp = content2;
						html += '<td>'+content2+'：'+'</td>';
					}else if(index2 == 'attr_input_type'){
						if(content2 == '列表中选择'){
							arr = str.split(',');
							html += '<td><select><option value="0">请选择</option>';
							for(var i=0; i<arr.length; i++){
								html += '<option value="0">' + arr[i] + '</option>';
							}
							html += '</select></td>';
						}else if(content2 == '手工录入'){
							html += '<td><input type="text" name="' + temp + '" /></td>';
						}else if(content2 == '多行文本框'){
							html += '<td><textarea name="' + temp + '" cols="40" rows="3"></textarea></td>';
						}
					}
					
				});
				html += '</tr>';
	
			});
			
			
			$(".trs").remove();
			$("#location").after(html);
		}

	}
	xhr.send(null);
	
	
}
*/